<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activIdsAdmin']))
{
	header("Location:checkLogin.php");
}
else
{
if(isset($_REQUEST['submit']) && $_REQUEST['company'] !="")
{
  $fName          = isset($_POST['fName']) ? $_POST['fName'] : "";
  $mName          = isset($_POST['mName']) ? $_POST['mName'] : "";
  $lName          = isset($_POST['lName']) ? $_POST['lName'] : "";
  $ph1            = isset($_POST['ph1']) ? $_POST['ph1'] : "";
  $ph2            = isset($_POST['ph2']) ? $_POST['ph2'] : "";
  $email          = isset($_POST['email']) ? $_POST['email'] : "";
  $web            = isset($_POST['web']) ? $_POST['web'] : "";
  $password       = isset($_POST['password']) ? $_POST['password'] : "";
  $company        = isset($_POST['company']) ? $_POST['company'] : "";
  
  $insertItem = "INSERT INTO user (company,fName,mName,lName,ph1,ph2,email,web,password,userType)
                           VALUES ('".$company."','".$fName."','".$mName."','".$lName."','".$ph1."','".$ph2."','".$email."','".$web."','".$password."','user')";
  $insertItemRes = mysql_query($insertItem);
  if(!$insertItemRes)
  {
  	die ("Insert Query Not Insertd :" .mysql_error());    
  }
  else
  {
    header("Location:createUser.php");
  }
}
$i=0;
$userArray = array();
$selectUser = "SELECT company,userId,fName,mName,lName,ph1,ph2,email,web,status,password
                 FROM user
                ORDER BY fName";
$selectUserRes = mysql_query($selectUser);
while($userRow = mysql_fetch_array($selectUserRes))
{
  $userArray[$i]['userId']     = $userRow['userId'];
  $userArray[$i]['company']    = $userRow['company'];
  $userArray[$i]['fName']      = $userRow['fName'];
  $userArray[$i]['mName']      = $userRow['mName'];
  $userArray[$i]['lName']      = $userRow['lName'];
  $userArray[$i]['ph1']        = $userRow['ph1'];
  $userArray[$i]['ph2']        = $userRow['ph2'];
  $userArray[$i]['email']      = $userRow['email'];
  $userArray[$i]['web']        = $userRow['web'];
  $userArray[$i]['status']     = $userRow['status'];
  $userArray[$i]['password']   = $userRow['password'];
  $i++;
}
include("bottom.php");
$smarty->assign("userArray",$userArray);
$smarty->display("createUser.tpl");
}
?>